<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <canvas id="canvas" style="border: 1px solid #aaa; display: block; margin: 50px auto;">
        当前浏览器不支持Canvas，请更换浏览器
    </canvas>
    <script>
        window.onload = function () {
            var canvas = document.getElementById("canvas");

            canvas.width = 800;
            canvas.height = 800;

            var context = canvas.getContext("2d");

            //使用context绘制

            context.lineWidth = 10;
            context.strokeStyle = '#005588';

            context.beginPath();
            context.moveTo(100, 200);
            context.lineTo(700, 200);
            context.lineCap = 'butt';
            context.stroke();

            context.beginPath();
            context.moveTo(100, 400);
            context.lineTo(700, 400);
            context.lineCap = 'round';  //圆形的头
            context.stroke();

            context.beginPath();
            context.moveTo(100, 600);
            context.lineTo(700, 600);
            context.lineCap = 'square';     //方形的头
            context.stroke();

            //baseline
            context.lineWidth = 1;
            context.strokeStyle = '#27a';
            context.moveTo(100, 100);
            context.lineTo(100, 700);
            context.moveTo(700, 100);
            context.lineTo(700, 700);
            context.stroke();
        }
    </script>
</body>
</html>